package com.example.tests;

import java.io.FileReader;
import java.util.Properties;
import java.util.logging.Logger;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

import com.example.fw.ApplicationManager;

public class TestBase {
    
	protected Logger log = Logger.getLogger("TEST");
	protected static ApplicationManager app;


	@BeforeTest
	@Parameters({"configfile"})
	public void setUp(@Optional String configfile) throws Exception {
        if (configfile == null){
        	configfile = System.getProperty("configfile");
        }
        if (configfile == null){
        	configfile = System.getenv("configfile");
        }
        if (configfile == null){
        	configfile = "application.properties";
        } 
        Properties props = new Properties();
        props.load(new FileReader(configfile));
        log.info("setUp start");
        app = ApplicationManager.getInstance(props);
        log.info("setUp end");
	  }
	
	@AfterTest
	public void tearDown() throws Exception {
		log.info("tearDown start");
		ApplicationManager.getInstance(null).stop();
		log.info("tearDown end");
	}
	

	

}
